<?php

class Billing_Model extends CI_Model {

    function __construct() {
        // Call the Model constructor
        parent::__construct();
    }
    
    function get_last_bill_no() {
      $bill_no_suffix = date('m').date('y');
      $sql = "SELECT bill_no FROM billing where bill_no like  '%".$bill_no_suffix."%' order by id desc  limit 1";
      $query = $this->db->query($sql);
      $data_result = $query->result_array();
      return $data_result;
    }

    function insert_bill_entry($data) {
        $this->db->insert('billing', $data);
        return $this->db->insert_id();
    }

    function getBillList($filter_sql = '', $page_info = null){
	$sql = "SELECT * FROM  billing ";

	if($filter_sql != NULL){
		$sql .= " WHERE " .$filter_sql;
	}
	$sql .= " order by bill_date desc";

	if (is_object($page_info)) {
		$offset = 0;
		$limit = 10;
		if ( $page_info->offset > 0) {
			$offset = $page_info->offset;
		}
		$limit = $page_info->limit;
		$val = (int) $limit;
		if ($val > 0 ){
			$sql .= ' limit ' . $offset . ", ". $limit ;
		}
	}


	$query = $this->db->query($sql);
	$dataresult =  $query->result_array();
	return $dataresult;
      }

      function getBillById($id) { 
	    $sql = "SELECT * FROM  billing where id=".$id;
            $query = $this->db->query($sql);
	    $dataresult =  $query->result_array();
	    return $dataresult;
      }

}